import { ref, onMounted } from "vue";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
import { getTopCategoryAPI } from "@/apis/category";

export function useCategory(){
    const categoryList=ref([]);
    const route=useRoute();
    async function getCateList(id=route.params.id){
        const res=await getTopCategoryAPI(id);
        categoryList.value=res.result
    }
    onMounted(() => {
        getCateList(route.params.id);
      });
      onBeforeRouteUpdate((to)=>{
        getCateList(to.params.id);
      })
    return categoryList
}